﻿Partial Public Class GameEngine
    ''' <summary>
    ''' Contains the collection of GameScene objects belonging to a GameEngine.
    ''' </summary>
    ''' <remarks></remarks>
    <System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)>
    Public Class GameEngineSceneCollection
        Inherits System.Collections.ObjectModel.KeyedCollection(Of String, GameScene)

        Private _Engine As GameEngine

        Public Sub New(ByVal forEngine As GameEngine)
            _Engine = forEngine
        End Sub

        Protected Overrides Function GetKeyForItem(ByVal item As GameScene) As String
            Return item.Name
        End Function

        Protected Overrides Sub ClearItems()
            For Each scene As GameScene In Me
                scene.SetEngine(Nothing)
            Next
            MyBase.ClearItems()
        End Sub

        Protected Overrides Sub InsertItem(ByVal index As Integer, ByVal item As GameScene)
            MyBase.InsertItem(index, item)
            item.SetEngine(_Engine)
            If Count = 1 Then
                item.Engine._CurrentSceneName = item.Name
            End If
        End Sub

        Protected Overrides Sub RemoveItem(ByVal index As Integer)
            Dim scene As GameScene = Item(index)
            scene.SetEngine(Nothing)
            MyBase.RemoveItem(index)
        End Sub

        Protected Overrides Sub SetItem(ByVal index As Integer, ByVal item As GameScene)
            MyBase.SetItem(index, item)
            item.SetEngine(_Engine)
        End Sub
    End Class
End Class

